<template>
  <div :class="{'mobile-dept-select-item-wrap':showMobilePage}" class="dept-select-item-wrap">
    <el-checkbox :value="isActive" @change="checkFun">
      <template v-if="deptInfo.departmentName && deptInfo.departmentName.length > 11">
        <ToolTip :content="`${deptInfo.departmentName}(${deptInfo.peopleNum}人)`"/>
      </template>
      <template v-else>
        {{ deptInfo.departmentName }}({{ deptInfo.peopleNum }}人)
      </template>
    </el-checkbox>
    <!-- <div style="flex: 1" /> -->
    <div :class="{ 'active': isActive }" class="next-level" @click.prevent="clickFun">
      <img :src="organIcon" >
      下级
    </div>
  </div>
</template>
<script>
import organIcon from '@/assets/organ_icon.png';
import { mapState } from 'vuex';
export default {
  name: 'DeptSelectItem',
  props: {
    isActive: {
      type: Boolean,
      default: false
    },
    deptInfo: {
      type: Object,
      default: () => {
        return null;
      }
    }
  },
  data() {
    return {
      organIcon
    };
  },
  computed: {
    ...mapState({
      'showMobilePage': state => state.app.showMobilePage
    })
  },
  methods: {
    clickFun() {
      if (this.isActive) return;
      this.$emit('click', this.deptInfo);
    },
    checkFun(val) {
      this.$emit('check', { isChecked: val, item: this.deptInfo });
    }
  }
};
</script>
<style lang="scss" scoped>
.dept-select-item-wrap {
  display: flex;
  cursor: pointer;
  padding: 12px 0;
  padding-left: 24px;
  .next-level {
    display: flex;
    align-items: center;
    width: 61px;
    padding: 0 8px;
    color: #999;
    font-size: 14px;
    border-left: 1px solid #eee;
    &.active {
      color: #ddd;
      cursor: not-allowed;
    }
    img {
      height: 13px;
      width: 12px;
      margin-right: 4px;
    }
  }
  & ::v-deep {
    .el-checkbox {
      flex: 1;
    }
    .el-checkbox__input.is-checked+.el-checkbox__label {
      color: #ddd;
    }
  }
  ::v-deep .el-checkbox__label {
    max-width: 15em;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: sub;
  }
}
.mobile-dept-select-item-wrap {
  ::v-deep .el-checkbox__label {
    white-space: normal;
    min-width: 120px;
    margin-right: 16px;
  }
}
.dept-select-item-wrap:hover {
  background-color: #F5F5F5;
}
</style>
